High-level and Low-level programming languages
Learning Objectives : Student will learn about -
Q1. a) What is a Computer Program?
✬ A set of instructions that directs a computer how to perform a specific task.
b) Describe Programming and explain what is meant by Programming Language.
✬ Programming is the process of writing a set of instructions called program or software.
✬ A Programming Language is a vocabulary and set of grammatical rules, for writing computational algorithm or program, to instruct a computer to perform specific tasks.
✬ Computer programs can be written in either Low-level or High-level languages depending on the task to be performed and the computer or digital device to be used.
✬ Mostly programs are written in high-level languages, like - BASIC, C, C++, Javascript, Pascal, Fortran, Python ... etc.,
c) What are the three types of programming language ?
- Machine Language.
- Assembly Language.
- High-level Language.
Note : Machine language and Assembly language are called Low-level language because they directly corresponds to a specific machine; use machine dependent codes; difficult for human to read and write.
Q2. a) Describe what is meant by Machine language.
✬ A digital language that uses 0s and 1s, which is the only language understood by computer is called machine language.
✬ The machine language is machine dependent. The manufacturer designs the machine code by a string of binary digits (bits) 0 and 1.
✬ Different types of computer system uses different set of binary instructions.
Example : 00010101 10110010 11110011
10111011 00010001 01011101
b) State two advantages and disadvantages of Machine language.
- Don't need any translator to translate the code.
- Machine specific codes can be used to write machine specific software, like device drivers.
- It's file size is too small and executes very fast.
- It is very difficult understand and tedious process of writing programs in machine languages.
- Need to remember machine specific codes and its different memory location addresses.
- It is very difficult to edit or debug the program.
Q3. a) Describe what is meant by Assembly language.
✬ A programming language that uses mnemonics codes (alphanumeric) and symbols.
✬ It is machine dependent codes. The codes written in one machine cannot be used in another.
✬ It is easier for the computer to understand but more difficult for the programmer to write.
✬ The instructions of the assembly language has to be converted into machine codes by a language translator called "Assembler" before execution.
Example : LDA #6ad
ADD #f3c
STO #46b
LDA means load value of the variable (held at location address #6ad) into the accumulator.
ADD means add value of variable (held at location address #f3c) to the value stored in the accumulator.
STO means replace the value of the variable (held in location address #46b) by the value stored in the accumulator.
b) State two advantages and disadvantages of Assembly language.
- Assembly language is easier to understand and use, than Machine language.
- Machine specific codes can be used to write machine specific software, like device drivers.
- It's file size is too small and executes very fast.
- Programmer needs to have the knowledge of the hardware and its machine specific codes.
- Need to remember different memory location addresses.
- It is difficult to edit or debug the program than high-level language.
Q4. a) What is Low-level language ?
✬ Assembly language which uses mnemonic codes and Machine language which uses only binary digits 0s and 1s are collectively called Low-level language.
✬ Low-level languages are machine dependent. It uses machine specific codes.
✬ Program written in one machine cannot be used in another machine.
b) Give difference between Machine language and Assembly language.
Machine language Assembly languageMachine language is only understand by the computers. Assembly language is only understand by human not by the computers. Machine language can only be represented by 0s and 1s. Assembly language uses mnemonics codes (alphanumeric) and symbols instead of 0s and 1s. Machine language do not need any translator. It needs Assembler to translate it into machine code before execution. Difficult to read, remember and write. Easy to read, remember and write than Machine language.
c) Explain why a programmer would choose to write a program in Low-level programming language even though it is tough to read and write.
✬ Low-level Assembly language uses processor specific mneumonic code that allows programmers to write highly optimized code for CPU to interact with hardware directly.
✬ It uses machine dependent codes so it is used to write programs for a specific hardware or device, like device drivers.
✬ It takes very less memory.
✬ It performs its task very quickly.
Q5. a) Describe High-level language ?
✬ A programming language that uses English-like statements and mathematical symbols; easy to read and write.
✬ It is machine independent codes. The codes written in one machine can be used in all machines.
✬ High-level language programmers don’t need to have hardware knowledge.
Example : INPUT "Enter the length : ", L
INPUT "Enter the width : ", W
Area = L * W
PRINT "Area of rectangle = ", Area
b) Give three advantages of using High-level language.
- Easy to read and understand as the language used is closer to human language.
- No need to have hardware knowledge.
- It is portable. Same program can be used on different computers.
- It is easy to debug and test programs.
- Easy to edit and update.
c) Give two disadvantages of using High-level language.
- Accessing and controlling hardware directly is difficult.
- It need to be translated into machine code before execution.
- It occupies more memory than low-level programs.
- High level programs are comparatively slower than low level programs.
Q6. Give difference between High-level and Low-level language.
High-level language Low-level languageEasy to read and write. Difficult to read and write. Uses machine independent code. Uses machine dependent code. Easy to modify. Difficult to modify. No need to have hardware knowledge. Deep hardware knowledge is needed. Slow in execution. Faster in execution.
Translators
Q7. What is meant by Translator ?
✬ Translator are system software which is used translates the human readable source codes into binary machine readable codes.
✬ It is a programming language processor that converts Low level (Assembly language) and High level programming language codes into machine codes.
✬ Translators are of three types :
Q8. Describe Assembler.
✬ Assemblers is a translation program used to convert the program written in Assembly language into Machine code.
✬ It converts the code line by line and produces an executable file.
✬ It is machine dependent.
✬ Once a program is assembled to the machine code, it can be directly used again and again to perform the same task.
Q9. Name and describe the translation program used to convert High-level language.
High-level programs could be translated into machine code by any one of the two translators -
⇒ Interpreter translates and executes the programming code each line at a time.
⇒ It produces error message whenever it encounters line by line, so it is easy to debug and test program during development.
⇒ It do not produce any separate executable file in machine code.
⇒ It is slower than compiler.
⇒ Compiler reads and translates the whole program in one go.
⇒ It produces a list of errors of whole program before translation.
⇒ It produce an object-code and a separate executable file in machine code, if there is no error in the source code.
⇒ It is faster than Interpreter.
Q10. Distinguish the difference between Object code and Machine code.
- Object code is a mid-level code between source code and machine code.
- Object code is a machine readable instruction but can't be executed directly by the CPU. [e.g. *.ELF (Executable Linking Format)].
Whereas Machine code is binary code that can be executed directly by the CPU. [e.g. *.EXE (Executable) file format]- Object code has to establish links to run-time library modules using specialized software called Linker to become executable program.
Q11. Give one Advantage and one Disadvantage of using Compiler.
- Source code is no longer needed once it is compiled to execute the program.
- A compiled program can be supplied as an executable file.
- Compiled programs run quickly, since they have already been translated.
- You can't change the program without the source code.
- The source code must be re-compiled every time the programmer changes the program.
- The machine code produced by the compiler, depends on target computer architecture like, its operating system and word size 16-bits, 64-bits, etc.
Q12. Give one Advantage and one Disadvantage of using Interpreter.
- Easier and quicker to debug and test programs during development.
- It is portable, because it translates and executes the code directly.
(The translation of source code depends on target computer's architecture which may vary from one computer to another.)
- Program cannot run without interpreter.
- Interpreted code runs slower.
- Do not produce machine code at all.
Q13. David is writing a program using a high-level language. The program will be published and sold for profit.
a) Describe why David prefer to use Interpreter when creating a computer program.
⇒ Interpreter translates high-level language source code one line of instruction at a time and execute it.
⇒ It would be easy to debug the program as it produces error each time when it encounters.
b) Describe why David needed to compile the program when he has completed it.
⇒ Compiler translates high-level language source code all at a time and produces a separate executable file.
⇒ This executable file could be sold as it could be used independently without source file or compiler.
Q14. Describe the difference between Compiler and Interpreter.
Compiler InterpreterReads and translates the whole high-level language program into machine code in one go. Reads, translates and executes a high-level program, one statement at a time. It produces a list of errors, if it encounters before translation. It produces only one error message, if it encounters while reading a statement. It takes a longer time to debug and test program during development. It is easy to debug and test program during development. An executable file of machine code is produced. No executable file of machine code is produced. Compiled programs are run without the compiler. Interpreted programs cannot run without the interpreter. A compiled program is usually distributed for general use. An interpreter is often used when a program is being developed.
Q15. Rizwan is writing a program to operate his newly designed drone. Give reason why he would prefers to write the program in low-level language.
⇒ Low-level Assembly language uses processor specific mnemonic code that allows programmers to write highly optimized code for CPU to interact with hardware directly.
⇒ Assembled programs are faster than high-level compiled programs and uses very less memory.
Q16. Describe the difference between Compiler and Assembler.
Compiler AssemblerCompiler is machine independent. Assembler is machine dependent. Compiler is used to convert High-level language into machine code. Assembler is used to convert low-level assembly language into machine code. Complier considers the entire code as one block, converts and produces an executable file. Assembler converts the code line by line and produces an executable file.
Integrated Development Environment (IDE)
Q1. a) What is meant by Source code in programming language ?
✬ Source code is the list of human-readable instructions that a programmer writes using simple text editor for the computer to perform some specific task.
✬ Source code can not be executed by computer until it is converted into Machine code, using Translator (like Assembler, Interpreter and Compiler).
✬ All Source code programs need to be translated before they can be executed unless they are written directly in Machine code.
b) Distinguish the differentiate between Syntax error and Logic error.
Syntax error : It is where a program statement doesn’t obey the rules of the programming language.
A program cannot be translated if it contains syntax errors.Logic error : It is where the program doesn’t do what the programmer wanted it to do.
Logic errors are found when a program is being run.
Q2. a) What is meant by Integrated Development Environment (IDE) ?
✬ An IDE is a suit of software development tools to write, test and develop a program in high-level language.
✬ IDE is an interface which provides Source code editor, Translator (Interpreter / Compiler), and Run-time environment to execute, debug and test the program.
b) Give three main features of an IDE and state its purpose.
IDE essentially contains -
- A Code editor : used to write and edit source code.
- A Compiler or interpreter : translates the source code into machine readable language and execute it.
- A Run-time environment with debugger : allows to execute, test and debug the program during development.
c) What are the benefits of using IDE for a programmer.
✬ IDE allows developing software without spending much time on language syntax.
✬ It offers predefined templates.
✬ No need to switch between multiple programs and applications. All the tools needed are available at one place within the IDE.
✬ It includes debugger which helps to prevent mistakes and provide instant feedback as the developer writes code.
Q3. Give five features of an IDE.
- Code editor.
- A translator.
- A Runtime environment with a debugger.
- Error diagnostics.
- Auto-completion.
- Auto-correction.
- An auto-documenter and prettyprinting.
Q4. Describe the following features of an IDE.
a) Code editor
⇒ Code editor allows a program to be written and edited without changing to a separate text editor.
⇒ It speeds up the program development process.
⇒ It provides auto-complete feature through prompts with text completion for variable names and reserved words.
b) Translator
⇒ IDE provides a translator, which could be either interpreter or compiler or both to convert source code into executable machine code.
⇒ Interpreter is often used for developing the program and the compiler is used to produce the final executable file to be used without source code.
c) Runtime environment with debugger
⇒ It allows to run and test the program line by line before completing the whole program.
⇒ It allows to set a breakpoint in the source code to stop execution of the program at that point.
⇒ A report window shows the contents of variables and expressions evaluated up to the set breakpoint in the program.
⇒ This allows the programer to see if there are any logic errors in the program and check that the program works as intended.
d) Error diagnostics and Auto-correction
⇒ Automatically check for error as the program code is being typed.
⇒ Alerts the programmer about the error in code and suggests possible correction by high-lighting the error.
⇒ It helps the programmer to correct the errors while writing a programming statement before going to the next.
e) Auto-documenter and pretty-printing
⇒ Auto documenter allows to create a document, that can be used by other developers to understand how and why the code was created. Describe what each variable, array and subroutine is used for. Explain the purpose of each function and modules used in the program and its expected outcomes or behaviour.
⇒ Pretty-printing feature allows to provide different colour to the key-words, programming statements, variables, numbers and text data in a meaningful way.
Example : Keywords in "blue", numerical data in "red", programming statements in "black", etc.
Q5. State the purpose of Error diagnostics in an IDE. Give an example of its use.
✬ Automatically check for error as the program code is being typed.
✬ Alert the programmer about the error in code and provide suggested correction by high-lighting the error.
✬ Allow the programmer to correct the error in code during the program development is in progress.
Example : 01 INPUT "Enter the number = " Num
08 PRENT Average
Error is underlined in red and description about errors is listed, like -
Error in Line-01 : Comma "," or a valid expression - continuation expected.
Error in Line-08 : Invalid function "PRENT".
Q6. a) State three different features of high-level programming language that a programmer could use to make sure that their program will be easier to understand by another programmer.
Give an example for each feature.
✬ Feature 1 : Easy to read, understand and debug as it uses simple english.
Example : INPUT Num / OUTPUT Result / IF Age >= 18 THEN OUTPUT "Eligible to vote". / REPEAT ... UNTIL Accept = TRUE
✬ Feature 2 : Allows to write comments (Documentation) – the statement marked as comment will not be considered as programming code.
Example : It allows to provide explanations and usage guidelines for others to understand the purpose of the codes. Like, Double forward slash ( // ) to comment in Java, Single quote (‘) to comment in VB.
✬ Feature 3 : Object oriented programming (OOP) – allows to organize code into classes and objects.
Example : Procedure and functions makes it easier to understand the program’s structure.
b) Give other three useful features of high-level language that could be used by the programmer.
✬ Feature 1 : Provides a well-defined Syntax.
Example : A well-defined way of writing programs makes it easy to understand, learn and write the program.
✬ Feature 2 : Availability of Library functions - It provides a large number of built-in functions to perform some specific task.
Example : To calculate the square-root of a number, the programmer can use the available built-in function without writing its own code.
✬ Feature 3 : Machine independent code.
Example : The program written in one computer with Intel Processor can be run on another computer having Motorola Processor.
REVISION : Statements and its key computing terms.
Machine code | a binary programming language, a program written in machine code can be loaded and executed without translation. |
High-level language (HLL) | a programming language that is independent of computer hardware, a program written in a HLL needs to be translated into machine code before it is executed. |
Low-level language (LLL) | a programming language that is dependent on a computer hardware, both machine code and assembly language are LLLs. |
Translator | converts a program written in a human readable language or a language which machine cannot read into machine code. |
Assembly language | a programming language that is dependent on computer hardware, a program written in an assembly language program needs to be translated into machine code before it is executed. |
Assembler | a computer program that translates programming code written in assembly language into machine code. |
Compiler | a computer program that translates a source program written in a high-level language to machine code. |
Interpreter | a computer program that reads, translates and executes a program written in a high-level language line by line. |
Integrated Development Environment (IDE) | a suite of programs used to write and test a computer program written in a high-level language. |
Debugging | finding errors in a computer program by running or tracing the program. |
Prettyprinting | displaying source code using different colours and formating, which make the code easier to read and understand. |
Report window | a separate window in the runtime environment of an IDE that shows the contents of variables during the execution of a program. |